package com.china08.yxyapi.api.home.kecheng.xiaoben;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLessonAuth;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.repository.db.YxyLessonsSchoolLessonAuthRepository;

/**
 * 校本课程--查询用户是否授权(true：已授权，false：未授权)
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class KechengXiaobenUserAuthSrhController extends YxyApiBaseController {

    @Autowired
    private YxyLessonsSchoolLessonAuthRepository yxyLessonsSchoolLessonAuthRepository;

    @RequestMapping(value = "/api_yw/home/kecheng/xiaoben/user/auth/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Boolean find(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {

        String userId = getProfile(request, response).getId();
        String lessonId = reqModel.lessonId;

        YxyLessonsSchoolLessonAuth yxyLessonsSchoolLessonAuths = yxyLessonsSchoolLessonAuthRepository
                .findByLessonIdAndUserId(lessonId, userId);
        if (yxyLessonsSchoolLessonAuths == null) {
            return false;
        } else {
            return true;
        }
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiPageReqModel {

        // 课程ID
        public String lessonId;
    }

}
